import { Component, OnInit, Input } from '@angular/core';
import { AppGlobalService } from '../../shared/service/app-global.service';
import { EventService } from '../../shared/service/event.service';
import { HttpService } from '../../shared/service/http.service';

@Component({
  selector: 'app-promotion-of-statistics',
  templateUrl: './promotion-of-statistics.component.html',
  styleUrls: ['./promotion-of-statistics.component.scss'],
})
export class PromotionOfStatisticsComponent implements OnInit {
  @Input() tagData: any;
  constructor(
    private appGlobalService: AppGlobalService,
    private eventService: EventService,
    private httpService: HttpService
  ) {
  }
  type: 1;
  ngOnInit() {
    // console.log('msg----->' + JSON.stringify(this.tagData));
  }

  // ngAfterViewInit(): void {
  //   //Called after ngAfterContentInit when the component's view has been initialized. Applies to components only.
  //   //Add 'implements AfterViewInit' to the class.
  //   if (this.tagData) {
  //     console.log('msg----->' + this.tagData.data);
  //   }
  // }

  ask2Days() {
    const that = this;
    const twoDaysDataBtn = document.getElementById("btn_" + this.tagData.data.buttonList[0].submit.id);
    const twoDaysDataP = document.getElementById("p_" + this.tagData.data.buttonList[0].submit.id);
    const allDataBtn = document.getElementById("btn_" + this.tagData.data.buttonList[1].submit.id);
    const allDataP = document.getElementById("p_" + this.tagData.data.buttonList[1].submit.id);
    twoDaysDataBtn.style.background = "rgba(182,183,191,1)";
    twoDaysDataBtn.style.border = "";
    twoDaysDataP.style.color = "rgba(255,255,255,1)";
    allDataBtn.style.background = "rgba(255,255,255,1)";
    allDataBtn.style.border = "0.06rem solid rgba(182,183,191,1)";
    allDataP.style.color = "rgba(182,183,191,1)";
    const params = {
      content: this.tagData.data.buttonList[0].submit.content,
      // { time: 2, opportunity_id: this.tagData.data.buttonList[0].submit.content.opportunity_id },
      id: this.tagData.data.buttonList[0].submit.id,
      sessionId: localStorage.getItem('sessionId')
    };
    this.httpService.post('application/submit', params, (res) => {
      if (res) {
        // console.log('msg----->' + typeof (res));
        that.tagData.data = res.data;
      }
    });
  }

  askAll() {
    const that = this;
    const twoDaysDataBtn = document.getElementById("btn_" + this.tagData.data.buttonList[0].submit.id);
    const twoDaysDataP = document.getElementById("p_" + this.tagData.data.buttonList[0].submit.id);
    const allDataBtn = document.getElementById("btn_" + this.tagData.data.buttonList[1].submit.id);
    const allDataP = document.getElementById("p_" + this.tagData.data.buttonList[1].submit.id);
    twoDaysDataBtn.style.background = "rgba(255,255,255,1)";
    twoDaysDataBtn.style.border = "0.06rem solid rgba(182,183,191,1)";
    twoDaysDataP.style.color = "rgba(182,183,191,1)";
    allDataBtn.style.background = "rgba(182,183,191,1)";
    allDataBtn.style.border = "";
    allDataP.style.color = "rgba(255,255,255,1)";
    const params = {
      content: this.tagData.data.buttonList[1].submit.content,
      // time: 0, opportunity_id: this.tagData.data.buttonList[1].submit.content.opportunity_id
      id: this.tagData.data.buttonList[1].submit.id,
      sessionId: localStorage.getItem('sessionId')
    };
    this.httpService.post('application/submit', params, (res) => {
      if (res) {
        // console.log('msg----->' + typeof (res));
        that.tagData.data = res.data;
      }
    });
  }

  gotoPage(obj) {
    if (!obj) {
      return;
    }
    const pageParams = {
      pageId: obj.link.target,
      params: obj.link.params,
      sessionId: localStorage.getItem('sessionId')
    };
    this.appGlobalService.goToForward(pageParams);
  }

}
